﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Net;
using System.IO;

public partial class CardCenter_OnlinePurchaseCardStep3 : System.Web.UI.Page
{
    WebUtility util = new WebUtility();
    private BLL.PaymentBean payBean;//包装支付接口信息
    private BLL.GetPaymentAccount getAccount;//获取支付接口信息

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Mobile"] == null || Session["totalMoney"] == null)
        {
            Response.Redirect("OnlinePurchaseCardStep1.aspx");
        }
        else 
        {
            this.Lbl_Mobile.Text = Session["Mobile"].ToString();
            this.Lbl_TotalMoney.Text = Session["totalMoney"].ToString();
        }
    }

    //另外加一个页面做支付页面
    //向支付页面提交数据 -- 跳转到支付页面 
    protected void ImgBtnGoPay_Click(object sender, ImageClickEventArgs e)
    {
        
        if (Session["ShoppingCat"] != null)
        {
            string payId = this.LianHuaOK.SelectedItem.Value;
            string selectedPayName = this.LianHuaOK.SelectedItem.Text;
            //把当前支付接口ID存入会话
            Session["payName"] = selectedPayName;

            //getAccount = new BLL.GetPaymentAccount();
            ////支付接口GUID标识
            //payBean = getAccount.getPayInfo(payId);
            ////支付页面
            //string paymentInterfaceUrl = payBean.PaymentInterfaceUrl;
            //string payName = payBean.PaymentName;//支付接口名
            ////参数：MerCode
            //string merchantAccount = payBean.MerchantAccount;//商户账号
            //string merchantPwd = payBean.MerchantPwd;//商户密码
            ////参数：Amount
            //string totalMoney = Session["totalMoney"].ToString();//支付金额
            ////参数：PayType
            //string payType = "01"; //全额支付
            //string merUrl = payBean.MerUrl;//支付接口返回数据页面，即回调页面
            ////参数：BillNo
            //string billNo = WebUtility.GenrateSerialPayNumber();//15位订单编号

            ////参数：SignMD5 [MD5(MerCode+BillNo+Amount+PayType+MerUrl+商户密码)]
            //string md5Info = WebUtility.getMd5CryptedStr(merchantAccount + billNo + totalMoney + payType + merUrl + merchantPwd);

            //////检测支付信息
            //if (!string.IsNullOrEmpty(merchantAccount) && !string.IsNullOrEmpty(merchantPwd) && !string.IsNullOrEmpty(totalMoney) &&
            //    !string.IsNullOrEmpty(merUrl) && !string.IsNullOrEmpty(billNo) && !string.IsNullOrEmpty(paymentInterfaceUrl))
            //{

            //    //向支付接口Post数据
            //    string postdata = "MerCode=" + merchantAccount;
            //    postdata += "&BillNo" + billNo;
            //    postdata += "&Amount" + totalMoney;
            //    postdata += "&PayType" + payType;
            //    postdata += "&MerUrl" + merUrl;
            //    postdata += "&SignMD5" + md5Info;

            //    byte[] data = Encoding.ASCII.GetBytes(postdata);
            //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(paymentInterfaceUrl);
            //    request.Method = "POST";
            //    request.ContentType = "application/x-www-form-urlencoded";
            //    request.ContentLength = data.Length;

            //    Stream stream = request.GetRequestStream();
            //    stream.Write(data, 0, data.Length);
            //    stream.Close();
            //}
            //else
            //{
            //    util.AlertMsg("支付接口错误,请及时联系网站管理员!");
            //}  


            //跳转到联华OK卡
            if (string.Equals(payId,"4C8DD9D9-A74C-4477-B5EF-0F9B3DB7FCDD"))
            {
                string url = "lianhuaOK.aspx?payId=" + payId;
                Response.Redirect(url);
            }
        }
        else 
        {
            Response.Redirect("OnlinePurchaseCardStep1.aspx");
        }
    }
    //返回购物车
    protected void ImgBtnReturnshoppingCart_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("OnlinePurchaseCardStep2.aspx");
    }
  
}
